YZYZ.Admin.Hotel.editWin 		= null;
YZYZ.Admin.Hotel.editForm 		= null;
YZYZ.Admin.Hotel.editLevelCB	= null;
YZYZ.Admin.Hotel.editStarCB		= null;
YZYZ.Admin.Hotel.showEditWin = function(){
	if(!YZYZ.Admin.Hotel.editWin){
		YZYZ.Admin.Hotel.editLevelCB = new Ext.form.ComboBox({  
	         id: 'editLevel', 
	         name:'level', 
	         allowBlank: false,  
	         fieldLabel: "显示级别",  
	         hiddenName: 'level',  
	         displayField: 'name',  
	         valueField: 'id',  
	         typeAhead: true,  
	         triggerAction: 'all',  
	         store: YZYZ.Admin.Hotel.levelStore,  
	         mode: 'local',
	         width:450 ,
	         editable:false
 		});
 		YZYZ.Admin.Hotel.editStarCB = new Ext.form.ComboBox({  
	         id: 'editStar', 
	         name:'status', 
	         allowBlank: false,  
	         fieldLabel: "酒店档次",  
	         hiddenName: 'status',  
	         displayField: 'name',  
	         valueField: 'id',  
	         typeAhead: true,  
	         triggerAction: 'all',  
	         store: YZYZ.Admin.Hotel.starStore,  
	         mode: 'local',
	         width:450 ,
	         editable:false
 		});
		YZYZ.Admin.Hotel.editForm = new Ext.form.FormPanel({
			labelWidth:100,
			autoScroll:true,
			width:650,
			height:400,
			region:'center',
			labelAlign:'right',
			bodyStyle:'padding-top:10px',
			items:[{
				fieldLabel:'名称',
				xtype:'textfield',
				width:450,
				maxLength:20,
				id:'editName',
				name:'name'	
			},{
				fieldLabel:'地址',
				xtype:'textfield',
				width:450,
				maxLength:40,
				id:'editLocation',
				name:'address'	
			},YZYZ.Admin.Hotel.editLevelCB,
			YZYZ.Admin.Hotel.editStarCB,
			{
				fieldLabel:'价格',
				xtype:'textarea',
				width:450,
				maxLength:40,
				id:'editPrice',
				name:'price',
				maxLength:300,
				height:40	
			},
			{
				xtype:'htmleditor',
				width:550,
				height:400,
				fieldLabel:'酒店描述',
				id:'editDescription',
				name:'description'
				
			}]
		});
		YZYZ.Admin.Hotel.editWin = new Ext.Window({
			title:'编辑酒店',
			width:700,
			height:400,
			layout:'border',
			closable:true,
			closeAction:'hide',
			modal:true,
			items:[YZYZ.Admin.Hotel.editForm],
			buttons:[{
				text:'提交',
				width:60,
				handler:YZYZ.Admin.Hotel.editSubmit
			},{
				text:'取消',
				width:60,
				handler:function(){YZYZ.Admin.Hotel.editWin.hide()}
			}]
		});
	}
	YZYZ.Admin.Hotel.editForm.getForm().loadRecord(YZYZ.Admin.Hotel.grid.getSelectionModel().getSelected());
	YZYZ.Admin.Hotel.editWin.show();
};
YZYZ.Admin.Hotel.editSubmit = function(){
	var name 		= Ext.getCmp("editName").getValue();
	var location	= Ext.getCmp("editLocation").getValue();
	var level		= Ext.getCmp("editLevel").getValue();
	var description = Ext.getCmp("editDescription").getValue();
	var star 		= Ext.getCmp("editStar").getValue();
	var price 		= Ext.getCmp("editPrice").getValue();
	if(Ext.isEmpty(name)){
		YZYZ.Curtain.alert("请填写名称");
		Ext.getCmp("editName").markInvalid();
		return;
	}
	if(name.length > 20){
		YZYZ.Curtain.alert("名称长度应小于20");
		Ext.getCmp("editName").markInvalid();
		return;
	}
	if(Ext.isEmpty(location)){
		YZYZ.Curtain.alert("请填写地址");
		Ext.getCmp("editLocation").markInvalid();
		return;
	}
	if(name.length > 40){
		YZYZ.Curtain.alert("地址长度应小于40");
		Ext.getCmp("editLocation").markInvalid();
		return;
	}
	if(Ext.isEmpty(price)){
		YZYZ.Curtain.alert("请填写价格");
		Ext.getCmp("editPrice").markInvalid();
		return;
	}
	if(Ext.isEmpty(star)) {
		YZYZ.Curtain.alert("请选择档次");
		Ext.getCmp("editStar").markInvalid();
		return;
	}
	if(Ext.isEmpty(description)){
		YZYZ.Curtain.alert("请填写描述");
		Ext.getCmp("editDescription").markInvalid();
		return;
	}
	if(description.length > 50000){
		YZYZ.Curtain.alert("描述长度应小于50000");
		Ext.getCmp("editDescription").markInvalid();
		return;
	}
	YZYZ.Curtain.msg("系统处理中....");
	Ext.Ajax.request( {
		url		: Ext.get("updateHotelUrl").dom.value,
		timeout	: 30000,
		method	: 'POST',
		params	: {
			name 		:  name,
			description	: description,
			address		: location,
			level		: level,
			star 		: star,
			hotelId 	: YZYZ.Admin.Hotel.grid.getSelectionModel().getSelected().get("id"),
			price 		: price
		},
		success : function(result, request) {
			result = Ext.util.JSON.decode(result.responseText);
			if(result.code == YZYZ.success){
				var rec = YZYZ.Admin.Hotel.grid.getSelectionModel().getSelected();
				rec.set("name", name);
				rec.set("description", description);
				rec.set("address", location);
				rec.set("status", star);
				rec.set("level", level);
				rec.set("price", price);
				YZYZ.Admin.Hotel.grid.getStore().commitChanges();
				YZYZ.Admin.Hotel.editWin.hide();
				YZYZ.Curtain.msg("修改成功");			
			}
			else {
				YZYZ.Curtain.alert(result.message);
			}
		},
		failure : function(result, request) {
			YZYZ.Curtain.alert("操作失败！程序错误或网络故障");
		}
	});	
	
};